package com.xunqi.permission.controller;

import com.xunqi.permission.beans.PageQuery;
import com.xunqi.permission.beans.PageResult;
import com.xunqi.permission.common.JsonData;
import com.xunqi.permission.param.SearchLogParam;
import com.xunqi.permission.pojo.SysLog;
import com.xunqi.permission.pojo.SysLogWithBLOBs;
import com.xunqi.permission.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "权限更新记录控制器")
@Controller
@RequestMapping(value = "/sys/log")
public class SysLogController {

    @Resource
    private SysLogService sysLogService;

    @ApiOperation(value = "跳转到权限更新记录页面",httpMethod = "GET",protocols = "HTTP",produces = "/log.json",response = String.class)
    @RequestMapping(value = "/log.page")
    public String page() {
        return "log";
    }

    @ApiOperation(value = "更新记录还原操作",httpMethod = "PUT",protocols = "HTTP",produces = "/recover.json",response = JsonData.class)
    @RequestMapping(value = "/recover.json")
    @ResponseBody
    public JsonData recover(@RequestParam("id") int id) {
        sysLogService.recover(id);
        return JsonData.success();
    }

    @ApiOperation(value = "权限更新记录分页展示并按多条件进行查询",httpMethod = "GET",protocols = "HTTP",produces = "/page.json",response = SysLog.class)
    @RequestMapping(value = "/page.json")
    @ResponseBody
    public JsonData searchPage(SearchLogParam param, PageQuery page) {
        PageResult<SysLogWithBLOBs> list = sysLogService.searchPageList(param,page);
        return JsonData.success(list);
    }

}
